$(function () {
    $("#comment_sub").click(function () {
        var content = $(".comment_input").val();
        var p_id = $(".comment_input").attr("p_id");
        if (!content) {
            return
        }
        params = {
            "content": content,
            "p_id": p_id
        };
        $.ajax({
            url: "/review.html",
            type: "post",
            data: JSON.stringify(params),
            contentType: "application/json",
            success: function (resp) {
                if (resp.errno == '0') {
                    comment = resp.comment;
                    comment_html = '';
                    comment_html += '<div class="review">';
                    comment_html += '<div class="user-img" style="background-image: url(' + comment.user.icon + ')"></div>';
                    comment_html += '<div class="desc">';
                    comment_html += '<h4>';
                    comment_html += '<span class="text-left">' + comment.user.name + '</span>';
                    comment_html += '<span class="text-right">' + comment.create_time + '</span>';
                    comment_html += '</h4>';
                    comment_html += '<p>' + comment.content + '</p>';
                    comment_html += '</div></div>';
                    console.log(comment_html);
                    $('.cart').prepend(comment_html);
                    // review_count = $("#review_count").text();
                    // $("#review_count").text(parseInt(review_count) + 1)
                    $(".comment_input").val('')
                } else if (resp.errno == "2001") {
                    window.location.href = "/signin.html"
                } else {
                    alert("评论失败")
                }
            }
        })

    })
});